<template>
    <div>
        <div class="bg"></div>
        <div class="topList">
            <router-link to="/appmain" class="topBtn">
               <i class="iconfont arrow-left">&#xe641;</i><span>心得体会</span>
            </router-link>
        </div>
        <div class="contentList">
            <div class="tipinfo">课程上完了说点什么吧！</div>
            <el-input
            type="textarea"
            :rows="11"
            placeholder="请在此处填写"
            v-model="textarea">
            </el-input>

             <div class="btnList">
                <el-button type="primary" @click="updateinfo">保存</el-button>
                <el-button  type="primary" @click="insertinfo">{{insert}}</el-button>
            </div> 
        </div>
       
        <div class="bottombar">
            <router-link to='/appmain'>
                <img src="../../assets/app/home.png" alt="">
            </router-link>
            
        </div>
           
    </div>
</template>

<script>
import { MessageBox, Toast } from "mint-ui";
export default {
  data() {
    return {
      textarea: null, //心得内容
      dt_id: null, //当前课堂编码
      studentinfo: null, //学员信息
      insert: "提交"
    };
  },
  //初始化
  mounted() {
    //初始化获取数据
    this.getinfo();
  },
  //事件
  methods: {
    //获取数据
    getinfo() {
      this.dt_id = localStorage.getItem("dt_id"); //获取课堂编码
      this.studentinfo = JSON.parse(localStorage.getItem("studentinfo")); //学员信息
      this.$axios
        .get("/Experience", { params: { Card: this.studentinfo.St_Card } })
        .then(Json => {
          if (Json.data == "no") {
            //没有提交
          } else {
            this.textarea = Json.data.Exp_Values; //数据获取
            if (Json.data.Exp_Flag == "1") {
              this.insert = "已提交";
            }
          }
        })
        .catch(err => {
          this.$message.error({
            message: "获取信息失败！请重新登录。。",
            type: "success",
            center: "true",
            offset: 300
          });
        });
    },
    //保存事件
    updateinfo() {
      if (this.insert == "已提交") {
        this.$message({
          message: "心得已经提交不能在修改",
          center: "true",
          offset: 300
        });
        return false;
      }
      this.listinfo(0, "保存");
    },
    //提交事件
    insertinfo() {
      if (this.insert == "已提交") {
        this.$message({
          message: "心得已经提交不能在修改",
          center: "true",
          offset: 300
        });
        return false;
      }
      MessageBox.confirm("提交后将无法再修改，是否继续?").then(action => {
        this.listinfo(1, "提交");
      });
    },

    //更新事件
    listinfo(Exp_Flag, name) {
      if (this.textarea.trim() == "") {
        this.$message({
          message: "心得不能为空",
          center: "true",
          offset: 300
        });
        return false;
      } else {
        var model = {
          Dt_Id: this.dt_id,
          Exp_Values: this.textarea,
          St_Card: this.studentinfo.St_Card,
          Exp_Flag: Exp_Flag
        };
        this.$axios
          .post("/Experience", model)
          .then(Json => {
            if (Json.data == "off") {
              this.$message({
                message: "没有学习课程之前不能提交心得",
                type: "warning",
                center: "true",
                offset: 300
              });
              return false;
            }
            if (Json.data == "ok") {
              this.$message({
                message: name + "成功",
                type: "success",
                center: "true",
                offset: 300
              });
              //初始化获取数据
              this.getinfo();
            } else {
              this.$message.error({
                message: "信息" + name + "失败！请重新" + name,
                type: "success",
                center: "true",
                offset: 300
              });
            }
          })
          .catch(err => {
            this.$message.error({
              message: "网络错误，请稍后重新尝试",
              type: "success",
              center: "true",
              offset: 300
            });
          });
      }
    }
  }
};
</script>

<style scoped>
.bg {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  /* background-image: linear-gradient( 135deg, #0396FF 10%, #ABDCFF 100%); */
  z-index: -1;
  width: 100%;
  /* height: 10rem; */
  background: #ececec;
}
@font-face {
  font-family: "iconfont"; /* project id 1514769 */
  src: url("//at.alicdn.com/t/font_1514769_4qk754zzrki.eot");
  src: url("//at.alicdn.com/t/font_1514769_4qk754zzrki.eot?#iefix")
      format("embedded-opentype"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.woff2") format("woff2"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.woff") format("woff"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.ttf") format("truetype"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.svg#iconfont") format("svg");
}
.iconfont {
  font-family: "iconfont" !important;
  font-size: 25px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  vertical-align: sub;
}
.topList {
  height: 11rem;
  width: 100%;
  line-height: 2.5rem;
  /* border:1px solid red; */
  text-align: center;
  font-size: 18px;
  background-image: linear-gradient(135deg, #0396ff 10%, #abdcff 100%);
}
.topBtn {
  text-decoration: none;
  color: white;
  display: inline-block;
  width: 100%;
}
.arrow-left {
  float: left;
}
.contentList {
  width: 90%;
  margin: -7rem auto;
  height: 25rem;
  /* border:1px solid red; */
  border-radius: 10px;
  background: white;
}
.tipinfo {
  text-align: center;
  padding: 1.8rem 0;
  color: cornflowerblue;
  font-size: 15px;
}
.el-textarea {
  padding: 0 15px;
  width: 90%;
}
.btnList {
  margin-top: 1rem;
  text-align: center;
}
.bottombar {
  position: fixed;
  z-index: 900;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  /* border: 1px solid white; */
  height: 50px;
  text-align: center;
  background: rgb(36, 164, 255);
  box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.1) inset;
}
.bottombar img {
  background: white;
  padding: 10px;
  border-radius: 50%;
  position: relative;
  /* top: -20px; */
  text-shadow: 0 1px rgba(0, 0, 0, 0.3);
  /* border: 5px solid gray; */
}
</style>
